﻿using System;
using Autodesk.Revit.DB;

namespace Assist
{
	public class DoorWinAssistFunc
	{
		public static XYZ GetInsertPt(FamilyInstance instance)
		{
			return (instance.Location as LocationPoint).Point;
		}

		public static double GetDoorWinWidth(FamilyInstance instance)
		{
			return AssistFunc.feetToMM(instance.Symbol.get_Parameter(BuiltInParameter.CASEWORK_WIDTH).AsDouble());
		}

		public static XYZ GetBoundPt(FamilyInstance instance, Wall host, int index)
		{
			XYZ point = (instance.Location as LocationPoint).Point;
			XYZ result = null;
			if (WallAssistFunc.GetWallCurveType(host) == WallCurveType.eLineWall)
			{
				XYZ startPt = WallAssistFunc.GetStartPt(host);
				XYZ xyz = new XYZ(point.X, point.Y, startPt.Z);
				XYZ xyz2 = (xyz - startPt).Normalize();
				if (index == 0)
				{
					result = xyz + xyz2 * AssistFunc.mmToFeet(DoorWinAssistFunc.GetDoorWinWidth(instance) / 2.0);
				}
				else if (index == 1)
				{
					result = xyz - xyz2 * AssistFunc.mmToFeet(DoorWinAssistFunc.GetDoorWinWidth(instance) / 2.0);
				}
			}
			else if (WallAssistFunc.GetWallCurveType(host) == WallCurveType.eArcWall)
			{
				Arc arc = (host.Location as LocationCurve).Curve as Arc;
				double num = AssistFunc.mmToFeet(DoorWinAssistFunc.GetDoorWinWidth(instance) / 2.0) / arc.Radius;
				num = ((index == 0) ? num : (-num));
				Transform transform = RevitVersionFuncs.CreateRotationAtPoint(arc.Normal, num, arc.Center);
				XYZ xyz3 = new XYZ(point.X, point.Y, WallAssistFunc.GetStartPt(host).Z);
				result = transform.OfPoint(xyz3);
			}
			return result;
		}
	}
}
